package com.linx.enterprise.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.mybatis.core.page.TableDataInfo;
import com.linx.common.web.core.BaseController;
import com.linx.enterprise.domain.bo.EnterpriseInfoBo;
import com.linx.enterprise.domain.vo.EnterpriseInfoVo;
import com.linx.enterprise.service.IEnterpriseInfoService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业信息
 *
 * @author linx
 * @date 2024-10-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/enterprise/enterprise-info")
public class EnterpriseInfoController extends BaseController {

    private final IEnterpriseInfoService enterpriseInfoService;

    /**
     * 查询企业信息列表
     */
    @SaCheckPermission("enterprise:enterprise-info:list")
    @GetMapping("/list")
    public TableDataInfo<EnterpriseInfoVo> list(EnterpriseInfoBo bo, PageQuery pageQuery) {
        return enterpriseInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出企业信息列表
     */
    @SaCheckPermission("enterprise:enterprise-info:export")
    @Log(title = "企业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EnterpriseInfoBo bo, HttpServletResponse response) {
        List<EnterpriseInfoVo> list = enterpriseInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "企业信息", EnterpriseInfoVo.class, response);
    }

    /**
     * 获取企业信息详细信息
     *
     * @param enterpriseInfoId 主键
     */
    @SaCheckPermission("enterprise:enterprise-info:query")
    @GetMapping("/{enterpriseInfoId}")
    public R<EnterpriseInfoVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long enterpriseInfoId) {
        return R.ok(enterpriseInfoService.queryById(enterpriseInfoId));
    }

    /**
     * 新增企业信息
     */
    @SaCheckPermission("enterprise:enterprise-info:add")
    @Log(title = "企业信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EnterpriseInfoBo bo) {
        return toAjax(enterpriseInfoService.insertByBo(bo));
    }

    /**
     * 修改企业信息
     */
    @SaCheckPermission("enterprise:enterprise-info:edit")
    @Log(title = "企业信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EnterpriseInfoBo bo) {
        return toAjax(enterpriseInfoService.updateByBo(bo));
    }

    /**
     * 删除企业信息
     *
     * @param enterpriseInfoIds 主键串
     */
    @SaCheckPermission("enterprise:enterprise-info:remove")
    @Log(title = "企业信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{enterpriseInfoIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] enterpriseInfoIds) {
        return toAjax(enterpriseInfoService.deleteWithValidByIds(List.of(enterpriseInfoIds), true));
    }


}
